package com.zhangxiaofanfan.hotcode.second;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode084 {
    public static void main(String[] args) {
        HotCode084 hotCode = new HotCode084();
        System.out.println(hotCode.numSquares(12));
    }

    public int numSquares(int n) {
        if (n == 1) {
            return 1;
        }
        int[] dp = new int[n + 1];
        dp[1] = 1;
        for (int i = 1, j; i <= n; i++) {
            int min = Integer.MAX_VALUE;
            for (j = 1; j * j <= i; j++) {
                min = Math.min(min, dp[i - j * j]);
            }
            dp[i] = min + 1;
        }
        return dp[n];
    }

}
